import 'package:flutter/material.dart';
import 'package:flutter_dk_form/src/bean/content_background_color_bean.dart';

import '../widget_text_radius_bg.dart';

/// 标题及内容标签Item(圆角背景标签)
/// [title]:标题
/// [data]:标签内容数组
/// [hasLine]：是否有下划线
class TitleContentsLabelItemWidget extends StatelessWidget {
  final String title;
  final List<ContentBackgroundColorBean> data;
  final bool hasLine;

  TitleContentsLabelItemWidget(
      {this.title = '', this.data, this.hasLine = true});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(left: 16, top: 18, right: 16, bottom: 18),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(title,
                    style: TextStyle(color: Color(0xFF999999), fontSize: 14)),
                SizedBox(
                  width: 10,
                ),
                Expanded(
                  child: Align(
                    alignment: Alignment.centerRight,
                    child: Wrap(
                      spacing: 10,
                      runSpacing: 10,
                      children: getWidgetList(),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Visibility(
              visible: hasLine,
              child:
                  Divider(height: 0.5, indent: 16, color: Color(0xFFEBEBEB))),
        ],
      ),
    );
  }

  List<Widget> getWidgetList() {
    List<Widget> widgets = List();
    data.forEach((item) {
      widgets.add(TextRadiusBgWidget(
          backgroundColor: item.backgroundColor,
          dataColor: 0xFFFFFFFF,
          dataSize: 12,
          topLeft: 63,
          topRight: 63,
          bottomLeft: 0,
          bottomRight: 63,
          data: item.content));
    });
    return widgets;
  }
}
